//src\main\preload.ts
const { contextBridge, ipcRenderer } = require('electron');
//将store挂载到window.electron下，待渲染进程调用
contextBridge.exposeInMainWorld('electron', {
  async getSize() {
    return ipcRenderer.sendSync('window_size');
  },
  store: {
    getItem(key) {
      return ipcRenderer.sendSync('electron-store-get', key);
    },
    setItem(property, val) {
      ipcRenderer.send('electron-store-set', property, val);
    },
    clear() {
      ipcRenderer.send('electron-store-clear');
    },
    path() {
      return ipcRenderer.sendSync('electron-store-path');
    },
  },
  async openCSV() {
    return await ipcRenderer.invoke('electron-get-csv');
  },
  async openNewWindow(url, specs, windowFlag) {
    ipcRenderer.send('open-window', url, specs,windowFlag);
  },
  async screenshot() {
    ipcRenderer.send('capture-screenshot');
  },
  async openPath(url = '') {
    ipcRenderer.send('open-path', url);
  },
  async errorPath(locality = '', localUrl = '', url = '') {
    return await ipcRenderer.sendSync('error-path', locality, localUrl, url);
  },
  async saveFile(file) {
    ipcRenderer.send('save-file', file);
  },
  async readFiles(filters, multiSelections) {
    return await ipcRenderer.invoke('read-file', filters, multiSelections);
  },
  async getLink(link) {
    return await ipcRenderer.sendSync('electron-link-get', link);
  },
  async getAllLink(link) {
    return await ipcRenderer.sendSync('electron-allLink-get', link);
  },
  async existsSync(link = '') {
    return await ipcRenderer.sendSync('exists-sync', link);
  },
  getAppPort() {
    return ipcRenderer.sendSync('app-post');
  },
  getAppSave() {
    return ipcRenderer.sendSync('app-save');
  },
  async deleteCommon(val = '') {
    return await ipcRenderer.sendSync('electron-common-clear', val)
  },
});
